package com.dh.str;

public class StringDemo01 {
    public static void main(String[] args) {
        String[] ss = {"苍井空", "枪", "杀"};
        String s = "苍井空拿着一把枪，去山上杀了三只虫子";
        for (String s1 : ss) {
            if (s.contains(s1)) {
                s = s.replace(s1, createStar(s1));
            }
        }
        System.out.println(s);
    }

    /**
     * 生成星星的方法
     *
     * @param content
     * @return
     */
    public static String createStar(String content) {
        int leg = content.length();//3
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < leg; i++) {
            sb.append("*");
        }
        return sb.toString();// 这必须toString ,因为要的是String类型的数据
    }
}
